home *** CD-ROM | disk | FTP | other *** search
- /* AB.C
- ************************************************************************
- * *
- * PC Scheme/Geneva 4.00 Borland C code *
- * *
- * (c) 1985-1988 by Texas Instruments, Inc. See COPYRIGHT.TXT *
- * (c) 1992 by L. Bartholdi & M. Vuilleumier, University of Geneva *
- * *
- *----------------------------------------------------------------------*
- * *
- * Assembly Beautifier *
- * *
- *----------------------------------------------------------------------*
- * *
- * Created by: L. Bartholdi Date: 1991 *
- * Revision history: *
- * - 18 Jun 92: Renaissance (Borland Compilers, ...) *
- * *
- * ``In nomine omnipotentii dei'' *
- ************************************************************************/
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
-
- char line[257], new[257], backup;
-
- char keywords[] = " proc segment ends endp macro endm extrn public ifdef "
- "if ifb ifdif ife ifidn ifnb ifndef include label db dw dd equ "
- "page model dosseg radix stack title subttl struc union "
- "comment assume group end .data .code .xcode .data? .stack "
- "else endif org ";
-
- char *mystrtok( char *s )
- {
- static char b[257], *src;
- char *p;
-
- if( s )
- {
- src = s;
- strcpy( b, s );
- }
- p = strtok( s, " \t");
- if( p && *p != ',')
- {
- p[strlen(p)] = b[p-src+strlen(p)];
- p = strtok( p, " \t,");
- }
- backup = b[p-src+strlen(p)];
- return p;
- }
-
- void parse( char *in, char *out )
- {
- static comment = 0;
- int col = 0, len;
- char cds[257];
-
- if( comment )
- {
- while( *in && *in != comment )
- *out++ = *in++;
- *out++ = *in;
- if( *in == comment )
- comment = 0;
- in++;
- } else
- if( isspace(*in) )
- {
- *out++ = '\t';
- col = 8;
- }
-
- in = mystrtok( in );
-
- do {
- top:
- len = strlen(in);
-
- if( *in == '\'')
- {
- in[len] = backup;
- do {
- *out++ = *in++;
- col++;
- } while( *in != '\'' && *in );
- *out++ = *in++;
- col++;
- if( *in == ',')
- {
- while( *in == ',')
- {
- *out++ = *in++;
- col++;
- }
- *out++ = ' ';
- col++;
- }
-
- if( mystrtok( in ) == NULL )
- break;
- else goto top;
- } else
- if( *in == '"')
- {
- in[len] = backup;
- do {
- *out++ = *in++;
- col++;
- } while( *in != '"' && *in );
- *out++ = *in++;
- col++;
- if( *in == ',')
- {
- while( *in == ',')
- {
- *out++ = *in++;
- col++;
- }
- *out++ = ' ';
- col++;
- }
- if( mystrtok( in ) == NULL )
- break;
- else goto top;
- }
-
- len = strlen(in);
-
- if( *in == ';')
- {
- in[len] = backup;
- if( col )
- while( col < 40 )
- {
- *out++ = '\t';
- col += 8;
- }
- strcpy( out, in );
- return;
- }
-
- strcpy( cds, in );
- if( strcmp( strupr(cds), in ) != 0 )
- strlwr( in );
- sprintf( cds, " %s ", in );
- if( strstr( keywords, cds ) )
- strupr( in );
-
- if( strcmp( in, "COMMENT") == 0 )
- {
- strcpy( out, in );
- out += strlen( out );
- *out++ = ' ';
- in = mystrtok( NULL );
- in[strlen(in)] = backup;
- comment = *in;
- strcpy( out, in );
- return;
- }
-
- strcpy( out, in );
- col += strlen( in );
- out += strlen( in );
- if( out[-1] == ':' && col < 16 )
- {
- *out++ = '\n';
- col = 0;
- }
-
- if( backup == ',')
- {
- *out++ = ',';
- col++;
- }
-
- if( out[-1] == ',' || col >= 15 || col == 8 || col == 9 )
- {
- *out++ = ' ';
- col++;
- } else {
- *out++ = '\t';
- col += 1 + ((255 - col) & 7);
- }
- } while( (in = mystrtok( NULL )) != NULL );
- *out = 0;
- }
-
- int main()
- {
- while( gets( line ) != NULL )
- {
- parse( line, new );
- puts( new );
- }
- return 0;
- }
-